home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / usr (gcc 1.37 libs) / mac / unlink.c < prev    next >
C/C++ Source or Header  |  1993-12-08  |  885b  |  42 lines

  1. #include <sys/types.h>
  2. #include <sys/syslimits.h>
  3. #include <fcntl.h>
  4. #include "crtlocal.h"
  5.  
  6. int unlink(const char *path1)
  7.     {
  8.     long filenum;
  9.     int i;
  10.     OSErr err;
  11.     FileParam pb;
  12.     mysleep(1);
  13.     pb.ioCompletion = 0;
  14.     pb.ioVRefNum = crt_ioVRefNum;
  15.     pb.ioFVersNum = 0;
  16.     pb.ioFDirIndex = 0;
  17.     pb.ioNamePtr = cnv_unix_name(path1);
  18.     err = PBGetFInfoSync((ParmBlkPtr)&pb);
  19.     if (err) return -1;
  20.     filenum = pb.ioFlNum;
  21.     for (i = 0; i < OPEN_MAX; i++)
  22.         {
  23.         if (crt_fd_tab[i].fd && !(crt_fd_tab[i].flags & O_PIPE)) 
  24.             {
  25.             FCBPBRec pb;
  26.             char name[99];
  27.             pb.ioRefNum = crt_fd_tab[i].fd;
  28.             pb.ioFCBIndx = 0;
  29.             pb.ioCompletion = 0;
  30.             pb.ioVRefNum = crt_ioVRefNum;
  31.             pb.ioNamePtr = (StringPtr) name;
  32.             PBGetFCBInfoSync(&pb);
  33.             if (pb.ioFCBFlNm == filenum) /* deleting open file */
  34.                 {
  35.                 PBCloseSync((ParmBlkPtr)&pb);
  36.                 }
  37.             }
  38.         }
  39.     err = PBDeleteSync((ParmBlkPtr)&pb);
  40.     return err?-1:0;
  41.     }
  42.